package 算法语言基础.Day12_7;

import java.util.Scanner;

public class Test19 {
    private static void Goldbach(int inputNum){
        //定义最大值，先赋予其最小值
        int max = Integer.MIN_VALUE;
        int maxOne = Integer.MIN_VALUE;
        int maxTwo = Integer.MIN_VALUE;
        // 筛法求素数
        int[] array = new int[inputNum];
        for (int i=2; i<inputNum; ++i){
            array[i] = i;
        }
        for (int i=2; i<inputNum; ++i){
            if (array[i]!=0){
                int j, temp;
                temp = array[i];
                for (j=2*temp; j<inputNum; j += temp){
                    array[j] = 0;
                }
            }
        }

        // show result
        for (int i=2; i<inputNum; ++i){
            if (array[i]!=0 && array[inputNum-i]!=0){
                if (array[i] > array[inputNum-i]) break;
//                System.out.println(inputNum + " = " + array[i] + "+" + array[inputNum-i]);
                int temp = array[i] * array[inputNum-i];    //定义乘积
                //找出乘计最大的两个数
                if(temp > max) {
                    max = temp;
                    maxOne = array[i];
                    maxTwo = array[inputNum-i];
                }
//                System.out.println(array[i] + " " + array[inputNum-i]);
            }
        }
        System.out.println(maxOne + "  " + maxTwo);     //输出找到的乘积最大的两个数
        System.out.println();
    }


    public static void main(String [] args){
        Scanner input = new Scanner(System.in);

        while (true){
            System.out.print("在输入一个偶数N(6<=N<=200000000):");
            int inputNum = input.nextInt();
            if (inputNum<6 || ((inputNum+1)%2==0)){
                System.out.println("Input Wrong!");
            } else {
                Goldbach(inputNum);
            }
        }
    }
}
